// 公共方法调用
import { useI18n } from '@/hooks/web/useI18n'
const { t } = useI18n()
import filetes from '@/utils/filters'

/**
 *@author lxc
 *@description:金额数量计算，千，万，十万....
 *@param:
 *@date: 2023-03-03 11:55:53
 **/
export const amountHit = (amount) => {
  if (amount == 0.0) {
    return ['', '']
  }
  const allUnits = [
    '个',
    '十',
    '百',
    t('amountUnits.qian'),
    t('amountUnits.wan'),
    t('amountUnits.shiWan'),
    t('amountUnits.baiWan'),
    t('amountUnits.qianWan'),
    t('amountUnits.yi'),
    t('amountUnits.shiYi'),
    t('amountUnits.baiYi'),
    t('amountUnits.qianYi')
  ]

  let amount2 = 0
  if (amount.toString().includes(',')) {
    amount2 = parseInt(amount.replace(/,/g, '').trim())
  } else amount2 = parseInt(amount)
  //if (amount2.toString().includes('.')) amount2 = Number(amount2.toString().split('.')[0]) //
  let units = ''
  if (amount2 >= 100000000000) {
    // eslint-disable-next-line vue/no-side-effects-in-computed-properties
    const amount3 = filetes.cutMoneyFiter(100000000000)
    // state.unit = allUnits[allUnits.length - 1]
    units = allUnits[allUnits.length - 1]
    return [units, amount3] //units
  }

  // let amountStrLen = amount.toString().length
  // if (amount.toString().includes('.')) {
  //   amountStrLen = amount.toString().split('.')[0].length
  // }
  const amountStrLen = amount2.toString().length
  if (amountStrLen > 3) units = allUnits[amountStrLen - 1]
  else units = ''
  return [units, amount]
}
